import rest
import wsgiref.handlers
import models
from google.appengine.api import urlfetch
from google.appengine.api import users
import urllib2
from google.appengine.ext import webapp

class MainPage(webapp.RequestHandler):
    def get(self):
        user = users.get_current_user()

        if not user:
            self.redirect(users.create_login_url(self.request.uri))
            
        self.response.out.write('<html><body>')
    
     
        
      
        url = "http://www.google.com/"
        result = urllib2.urlopen(url)
        #result = urlfetch.fetch(url)
        self.response.out.write(result.content)
        self.response.out.write("Hello World1llsss")

        self.response.out.write('</body></html>')
    
application = webapp.WSGIApplication([
  ('/', MainPage),
  ('/rest/.*', rest.Dispatcher)
], debug=True)
# configure the rest dispatcher to know what prefix to expect on request urls
rest.Dispatcher.base_url = "/rest"
rest.Dispatcher.add_models_from_module('models')

def main():
    wsgiref.handlers.CGIHandler().run(application)
    
    info=models.GreetingInfo(key_name="info")
    info.put()
    
    greeting = models.Greeting(key_name="greeting1")
    greeting.author=users.get_current_user()
    greeting.content = "Some Content"
    greeting.info=info.key()
    greeting.put()

if __name__ == '__main__':
    
    main()